<?php
/**
 * @FileName:area_managerment.php
 * @Describe:TODO
 * @Author:Arthur
 * @Email:arthurkingtoo@foxmail.com
 * @Time:2012-8-14
 * @Version:V9.0
 */
  require_once(dirname(__FILE__)."/../config/config.php");
  $level =$_REQUEST['level'];
  	if(empty($level))
  	{
  		$level = 1;
  	}
  	$id = $_REQUEST['id'];
  //添加城市
  $method = $_REQUEST['method'];
  if($method == 'insert')
  {
  	$type="";
  	$parentId =$_REQUEST['parentId'];
  	if(empty($parentId))
  	{
  		$parentId=0;
  	}
  	$level =$_REQUEST['level'];
  	$name = $_REQUEST['name'];
  	if(!empty($_REQUEST['type']))
  	{
  	$type =implode("|",$_REQUEST['type']);
  	}
  	$sql="insert into zy_businessarea (name,level,parentId,type) values ('$name',$level,$parentId,'$type')";
	if($name!=""){
  	mysql_query($sql);
	}else{
		$error="请填写正确！";
	}
  	if($level == 1)
	  {
	  	header("location:area_managerment.php");
	  }
	  else
	  {
	  	header("location:districtList.php");
	  }
  }
  
  if($method == "updates")
  {
  	$id = $_REQUEST['id'];
  	$type="";
  	$parentId =$_REQUEST['parentId'];
  	if(empty($parentId))
  	{
  		$parentId=0;
  	}
  	$level =$_REQUEST['level'];
  	$name = $_REQUEST['name'];
  	if(!empty($_REQUEST['type']))
  	{
  		$type =implode("|",$_REQUEST['type']);
  	}
	if($name!=""){
  	$sql="update zy_businessarea set name='$name',level=$level,parentId=$parentId,type='$type' where id=$id";
  	mysql_query($sql);
  	header("location:districtList.php");
	}else{
		echo "请正确填写！";
	}
  }
  
  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>城市添加信息</title>
</head>
<body>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
<h1 align="center">城市添加信息</h1>
<form id="form1" name="form1" method="post" action="area_managerment.php?method=<?php if($method == "inserto"){echo "insert";}elseif($method == "update"){echo "updates";}else{echo "insert";}
 ?>">
  <table width="500" height="30" align="center" border="1">
  <input type="hidden" name="id" id="id" value="<?php echo $id;?>"/>
    <?php if($level == 1){
    	if(!empty($id))
    	{
    	$sqlrs="select * from zy_businessarea where id=".$id." and level=".$level;
	  	$rss = mysql_query($sqlrs);
	  	$resultas = mysql_fetch_array($rss);
    	}
    	?>
   <tr>
      <td width="200" height="30" align="center">城市</td>
      <td width="300" height="30" align="center">
      	<input type="text" name="name" id="name" size="30" value="<?php echo $resultas['name'];?>"/>
      	<input type="hidden" id="level" name="level" value="1"/>
      </td>
    </tr>
      <?php }?>
      <?php if($level == 2){?>
     <tr>
      <td width="200" height="30" align="center">城市</td>
      <td width="300" height="30" align="center">
      	<select name="parentId" id="parentId" style="width:73%">
      	 <?php 
      	 	$sql="select * from zy_businessarea where id=".$id." and level=".$level;
	  		$rs = mysql_query($sql);
	  		$result4 = mysql_fetch_array($rs);
      		$sqlname = "select zy_businessarea.* from zy_businessarea where level=1";
      		$result = mysql_query($sqlname);
      		while($resultCity = mysql_fetch_array($result)){
      ?>
			<?php
			if($method == 'update'){
			?>
			<option value="<?php echo $resultCity['id']?>" <?php if($result4['parentId'] == $resultCity['id']){echo "selected='selected'";}
			?>><?php echo $resultCity['name']?></option>
			<?php }else{?>
				<option value="<?php echo $resultCity['id']?>" <?php if($id == $resultCity['id']){echo "selected='selected'";}
			?>><?php echo $resultCity['name']?></option>
			<?php }}?>
		</select>
      </td>
    </tr>
    <tr>
    	<td width="200" height="30" align="center">区域</td>
        <td width="200" height="30" align="center">
        	<input type="text" name="name" id="name" size="30" value="<?php echo $result4['name'];?>"/>
        	<input type="hidden" id="level" name="level" value="<?php echo $level;?>"/>
        </td>
    </tr>
    <?php }?>
    <?php if($level == 3){?>
    <tr>
      <td width="200" height="30" align="center">区域</td>
      <td width="300" height="30" align="center">
      	<select name="parentId" id="parentId" style="width:73%">
      	 <?php 
      	 	$sql="select * from zy_businessarea where id=".$id." and level=".$level;
	  		$rs = mysql_query($sql);
	  		$result = mysql_fetch_array($rs);
      		$sqlarea = "select zy_businessarea.* from zy_businessarea where level=2";
      		$resultarea = mysql_query($sqlarea);
      		while($resultareas = mysql_fetch_array($resultarea)){
      ?>
			<?php
			if($method == 'update'){
			?>
			<option value="<?php echo $resultareas['id']?>" <?php if($result['parentId'] == $resultareas['id']){echo "selected='selected'";}
			?>><?php echo $resultareas['name'];?></option>
			<?php }else{?>
			<option value="<?php echo $resultareas['id']?>" <?php if($id == $resultareas['id']){echo "selected='selected'";}
			?>><?php echo $resultareas['name'];?></option>
			<?php }}?>
		</select>
      </td>
    </tr>
    <tr>
    	<td width="200" height="30" align="center">商圈</td>
        <td width="200" height="30" align="center">
        	<input type="text" name="name" id="name" size="30" value="<?php echo $result['name'];?>"/>
        	<input type="hidden" id="level" name="level" value="<?php echo $level;?>"/>
        </td>
    </tr>
    <?php }?>
     <?php if($level == 4){?>
     	<tr>
      <td width="200" height="30" align="center">商圈</td>
      <td width="300" height="30" align="center">
      	<select name="parentId" id="parentId" style="width:73%">
      	 <?php 
      	 	$sql="select * from zy_businessarea where id=".$id." and level=".$level;
	  		$rs = mysql_query($sql);
	  		$result = mysql_fetch_array($rs);
      		$sqlbusiness = "select zy_businessarea.* from zy_businessarea where level=3";
      		$resultbusiness = mysql_query($sqlbusiness);
      		while($resultbusines = mysql_fetch_array($resultbusiness)){
      ?>
			<?php
			if($method == 'update'){
			?>
			<option value="<?php echo $resultbusines['id']?>" <?php if($result['parentId'] == $resultbusines['id']){echo "selected='selected'";}
			?>><?php echo $resultbusines['name'];?></option>
			<?php }else{?>
			<option value="<?php echo $resultbusines['id']?>" <?php if($id == $resultbusines['id']){echo "selected='selected'";}
			?>><?php echo $resultbusines['name'];?></option>
			<?php }}?>
		</select>
      </td>
    </tr>
    <tr>
    	<td width="200" height="30" align="center">地址</td>
        <td width="200" height="30" align="center">
        	<input type="text" name="name" id="name" size="30" value="<?php echo $result['name'];?>"/></br>
        	<input type="checkbox" class="checkbox" name="type[]" value="[1]" <?php if(strpos($result['type'],"1")){echo "checked='checked'";}?>/>大学
        	<input type="checkbox" class="checkbox" name="type[]" value="[2]" <?php if(strpos($result['type'],"2")){echo "checked='checked'";}?>/>小区
        	<input type="checkbox" class="checkbox" name="type[]" value="[3]" <?php if(strpos($result['type'],"3")){echo "checked='checked'";}?>/>写字楼
        	<input type="hidden" id="level" name="level" value="<?php echo $level;?>"/>
        </td>
    </tr>
     <?php }?>
  </table>
  <h3 align="center"><input type="submit" class="submit button" name="submit" value="保存" />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="admin_management.php">返回</a>
  </h3>
</form>
</body>
</html>
